home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / SRC / HOARDDLL.ZIP / 3rdParty / hoard / libhoard-2.0.2 / heapstats.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-15  |  3.3 KB  |  174 lines

  1. ///-*-C++-*-//////////////////////////////////////////////////////////////////
  2. //
  3. // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
  4. //        for Shared-Memory Multiprocessors
  5. // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
  6. //
  7. // Copyright (c) 1998-2000, The University of Texas at Austin.
  8. //
  9. // This library is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU Library General Public License as
  11. // published by the Free Software Foundation, http://www.fsf.org.
  12. //
  13. // This library is distributed in the hope that it will be useful, but
  14. // WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. #ifndef _HEAPSTATS_H_
  20. #define _HEAPSTATS_H_
  21.  
  22. #include "config.h"
  23.  
  24. #include <stdio.h>
  25. #include <assert.h>
  26.  
  27.  
  28. class heapStats {
  29. public:
  30.  
  31.   heapStats (void)
  32.     : 
  33.     U (0),
  34.     A (0)
  35. #if HEAP_STATS
  36.     ,Umax (0),
  37.     Amax (0)
  38. #endif
  39.   {}
  40.  
  41.   inline const heapStats& operator= (const heapStats& p);
  42.  
  43.   inline void incStats (int updateU, int updateA);
  44.   inline void incUStats (void);
  45.  
  46.   inline void decStats (int updateU, int updateA);
  47.   inline void decUStats (void);
  48.   inline void decUStats (int& Uout, int& Aout);
  49.  
  50.   inline void getStats (int& Uout, int& Aout);
  51.  
  52.  
  53. #if HEAP_STATS
  54.   
  55.   inline int getUmax (void);
  56.   inline int getAmax (void);
  57.  
  58. #endif
  59.  
  60.  
  61. private:
  62.  
  63.   // U and A *must* be the first items in this class --
  64.   // we will depend on this to atomically update them.
  65.  
  66.   int U;    // Memory in use.
  67.   int A;    // Memory allocated.
  68.  
  69. #if HEAP_STATS
  70.   int Umax;
  71.   int Amax;
  72. #endif
  73. };
  74.  
  75.  
  76. inline void heapStats::incStats (int updateU, int updateA) 
  77. {
  78.   assert (updateU >= 0);
  79.   assert (updateA >= 0);
  80.   assert (U <= A);
  81.   assert (U >= 0);
  82.   assert (A >= 0);
  83.   U += updateU;
  84.   A += updateA;
  85. #if HEAP_STATS
  86.   Amax = MAX (Amax, A);
  87.   Umax = MAX (Umax, U);
  88. #endif
  89.   assert (U <= A);
  90.   assert (U >= 0);
  91.   assert (A >= 0);
  92. }
  93.  
  94.  
  95. inline void heapStats::incUStats (void)
  96. {
  97.   assert (U < A);
  98.   assert (U >= 0);
  99.   assert (A >= 0);
  100.   U++;
  101. #if HEAP_STATS
  102.   Umax = MAX (Umax, U);
  103. #endif
  104.   assert (U >= 0);
  105.   assert (A >= 0);
  106. }
  107.  
  108.  
  109. inline void heapStats::decStats (int updateU, int updateA)
  110. {
  111.   assert (updateU >= 0);
  112.   assert (updateA >= 0);
  113.   assert (U <= A);
  114.   assert (U >= updateU);
  115.   assert (A >= updateA);
  116.   U -= updateU;
  117.   A -= updateA;
  118.   assert (U <= A);
  119.   assert (U >= 0);
  120.   assert (A >= 0);
  121. }
  122.  
  123.  
  124. inline void heapStats::decUStats (int& Uout, int& Aout) 
  125. {
  126.   assert (U <= A);
  127.   assert (U > 0);
  128.   assert (A >= 0);
  129.   U--;
  130.   Uout = U;
  131.   Aout = A;
  132.   assert (U >= 0);
  133.   assert (A >= 0);
  134. }
  135.  
  136.  
  137. inline void heapStats::decUStats (void) 
  138. {
  139.   assert (U <= A);
  140.   assert (U > 0);
  141.   assert (A >= 0);
  142.   U--;
  143. }
  144.  
  145.  
  146. inline void heapStats::getStats (int& Uout, int& Aout) 
  147. {
  148.   assert (U >= 0);
  149.   assert (A >= 0);
  150.   Uout = U;
  151.   Aout = A;
  152.   assert (U <= A);
  153.   assert (U >= 0);
  154.   assert (A >= 0);
  155. }
  156.  
  157.  
  158. #if HEAP_STATS
  159. inline int heapStats::getUmax (void) 
  160. {
  161.   return Umax;
  162. }
  163.  
  164.  
  165. inline int heapStats::getAmax (void) 
  166. {
  167.   return Amax;
  168. }
  169. #endif // HEAP_STATS
  170.  
  171.  
  172.  
  173. #endif // _HEAPSTATS_H_
  174.